package org.x.yuenovel.dao;

import org.springframework.stereotype.Repository;
import org.x.yuenovel.dao.mapper.UserInfoMapper;
import org.x.yuenovel.domain.UserInfo;
import org.x.yuenovel.domain.UserInfoExample;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xuezhendong
 * @date 2022/4/15 10:20 下午
 */
@Repository
public class UserInfoDao {

    @Resource
    private UserInfoMapper userInfoMapper;

    /**
     * 使用邮箱查询用户
     *
     * @param mail mail
     * @return list
     */
    public List<UserInfo> getUserInfoListByMailOrName(String mail, String name) {
        UserInfoExample example = new UserInfoExample();
        UserInfoExample.Criteria criteria = example.createCriteria();
        criteria.andMailEqualTo(mail);
        UserInfoExample.Criteria or = example.createCriteria();
        or.andUsernameEqualTo(name);
        return userInfoMapper.selectByExample(example);
    }

    public List<UserInfo> queryUserByUsername(String username) {
        UserInfoExample example = new UserInfoExample();
        UserInfoExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        return userInfoMapper.selectByExample(example);
    }

    public int createUser(UserInfo userInfo) {
        return userInfoMapper.insertSelective(userInfo);
    }
}